//---------------------主要部分------------------------------
		//activeObj:触发时间的元素id
		//contObj:要显示内容的id
		//clearObj:清除显示层的id
		//newDivWidth:显示层的宽度
		//newDivHeight:显示层的高度
var popContentHTML = "";
var contentObj = undefined;
var isie6 = window.XMLHttpRequest?false:true;
function openPopWindow(activeObj,contObj,clearObj,newDivWidth,newDivHeight,callback){
	var oletter=document.getElementById(activeObj);
	var lettercont=document.getElementById(contObj);
	var oclearbox=document.getElementById(clearObj);	
	oletter.onclick=function(){
			//_hiddenSelect();
			box_createDiv(lettercont,newDivWidth,newDivHeight, null, callback);
		}
}
function openPopWindowEx(activeObj,contObj,clearObj,newDivWidth,newDivHeight,callback){
	var oletter=document.getElementById(activeObj);
	var lettercont=document.getElementById(contObj);
	var oclearbox=document.getElementById(clearObj);	
	box_createDiv(lettercont,newDivWidth,newDivHeight, null, callback);
	
}

function popwindow_show(contentItemId, popupWidth, popupHeight,contentHTML,callback) {
	var item = document.getElementById(contentItemId);
	//_hiddenSelect();
	box_createDiv(item, popupWidth, popupHeight,contentHTML, callback);
    
}
/*
function _hiddenSelect(){//查找并隐藏select
	var oselect=document.getElementsByTagName("select");
	if(oselect.length>0){
		for(var i=0;i<oselect.length;i++){
			oselect[i].style.visibility="hidden";
		}
	}
}	
function showselect(){//显示select
	var oselect=document.getElementsByTagName("select");
	if(oselect.length>0){
		for(var i=0;i<oselect.length;i++){
			if(oselect[i].style.visibility=="hidden"){
				oselect[i].style.visibility="visible";
			}
		}
	}
}
*/
function owinWidth(){//当前窗口的width
		var winWidth;
		if (window.innerWidth){
   			winWidth = window.innerWidth;
		}
   		else if ((document.body) && (document.body.clientWidth)){
   			winWidth = document.body.clientWidth;
		}
   		if (document.documentElement  && document.documentElement.clientWidth){
   			winWidth = document.documentElement.clientWidth;
		}
		return winWidth;
}
function owinHeight(){//当前窗口的height
		var winHeight;
		if (window.innerHeight){
   			winHeight = window.innerHeight
		}else if ((document.body) && (document.body.clientHeight)){
   			winHeight = document.body.clientHeight
		}
		if (document.documentElement  && document.documentElement.clientHeight){
   			winHeight = document.documentElement.clientHeight;
		}
		return winHeight;	
}
function box_createDiv(pinner,newDivWidth,newDivHeight, contentHTML, call_back){//创建背景
	var obody=document.body;
	var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
	document.documentElement.style.overflowY="auto";
	document.documentElement.style.overflowX="hidden";
	var newDiv=document.createElement("div");
	newDiv.id="bgdiv";
	newDiv.style.width = "100%";
	newDiv.style.zIndex = 99990;
	if(isie6){
		newDiv.innerHTML = "<iframe class=\"divshim\"></iframe>";
	}
	var winWidth=owinWidth();
	var winHeight=owinHeight();
	if(obody.offsetHeight>winHeight){
		newDiv.style.height=obody.offsetHeight+"px";
	}else{
		newDiv.style.height=winHeight+'px';
	}
	newDiv.style.background="#000";
	newDiv.style.position="absolute";
	if(typeof(newDiv.style.filter)=="string"){
		newDiv.style.filter="alpha(opacity=30)";
	}else{
		newDiv.style.opacity="0.3";
	}
	newDiv.style.top=0;
	newDiv.style.left=0;
	//var newP=city_createP(winWidth,winHeight,newDivWidth,newDivHeight);
	var newP = city_createP(iWidth, iHeight, newDivWidth, newDivHeight);
	var titleBar = document.createElement("div");
	titleBar.id = "titlebar";
	titleBar.title = "按住鼠标可拖动";
	titleBar.innerHTML = "";
	obody.appendChild(newDiv);
	obody.appendChild(newP);
	
	setTimeout( function () {
		if(pinner){
			newP.innerHTML = pinner.innerHTML;
			popContentHTML = pinner.innerHTML;
			pinner.innerHTML = "";
			contentObj = pinner;
		}
		else{
			newP.innerHTML = contentHTML;
		}
		newP.appendChild(titleBar);
		box_drag(newP, titleBar);
		
		if (call_back) {
			call_back();
		}
	}, 100);
	
	//_show(newP, winWidth, winHeight, 0, 0, newDivWidth, newDivHeight, 50, 40, 1);
}
function box_drag(contentObj, moveObj){
	var moveX = 0;
    var moveY = 0;
    var moveTop = 0;
    var moveLeft = 0;
    var moveable = false;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;
    moveObj.onmousedown = function() {
		var evt = getEvent();
		if(moveObj.setCapture){
			moveObj.setCapture();
		}else if(window.captureEvents){
			window.captureEvents(evt.MOUSEMOVE | evt.MOUSEUP);
		}
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(contentObj.style.top);
        moveLeft = parseInt(contentObj.style.left);

        document.onmousemove = function() {
			if (moveable) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
                if (y > 0 && y < document.body.scrollHeight - contentObj.offsetHeight && x > 0 && x < document.body.offsetWidth - contentObj.offsetWidth) {
                    contentObj.style.left = x + "px";
                    contentObj.style.top = y + "px";
                }
            }
        };
        document.onmouseup = function () {
			if(moveObj.releaseCapture){
				moveObj.releaseCapture();
			}else if(window.captureEvents){
				window.captureEvents(evt.MOUSEMOVE|evt.MOUSEUP);
			}
			if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;
                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }
}
function _show(item, winWidth, winHeight, width, height, maxWidth, maxHeight, stepWidth, stepHeight, timeout) {
	if (width >= maxWidth) {
		width = maxWidth;
	}
	if (height >= maxHeight) {
		height = maxHeight;
	}

	item.style.marginTop = - item.offsetHeight / 2 + "px";
	item.style.marginLeft = - item.offsetWidth / 2 + "px";

	item.style.width = width + "px";

	item.style.height = height + "px";
	
	if (width == maxWidth && height == maxHeight) {
		return;
	}
	_show(item, winWidth, winHeight, width + stepWidth, height + stepHeight, maxWidth, maxHeight, stepWidth, stepHeight, timeout);
}
function city_createP(winWidth,winHeight,newDivWidth,newDivHeight){//创建显示层
	var obody=document.body;
	var newP=document.createElement("div");
	newP.id="contdiv";
	newP.className="pop_new_p";
	newP.style.width=newDivWidth+"px";
	newP.style.height=newDivHeight+"px";
	newP.style.zIndex = 99991;
	//newP.style.background="#fff";
	if(newDivHeight > winHeight){
		newP.style.top = document.documentElement.scrollTop + document.body.scrollTop + "px";
	}
	else{
		//if(isie6){
			newP.style.top = (winHeight - newDivHeight) / 2 + document.documentElement.scrollTop + document.body.scrollTop + "px";
		//}else{
			//newP.style.top= (winHeight - newDivHeight) / 2 + "px";
		//}
	}
	newP.style.left= (winWidth - newDivWidth)/2 + "px";
	return newP;
}
function box_clearDiv(){//清除生成背景和容器层
	var bgd=document.getElementById("bgdiv");
	var contd=document.getElementById("contdiv");
    if(contd)
        document.body.removeChild(contd);
    if(bgd)
        document.body.removeChild(bgd);
	document.documentElement.style.overflowY="auto";
	//showselect();
    if(contentObj)
        contentObj.innerHTML = popContentHTML;
}
function popwindow_close(callbackFn){
    box_clearDiv();
    if(callbackFn)
        callbackFn();
}
// 获得事件Event对象，用于兼容IE和FireFox 
function getEvent(){
	return window.event || arguments.callee.caller.arguments[0];
}